import React, {lazy} from 'react'
import {Route, useRoutes} from 'react-router-dom'
import {IMenu} from "@/common/model/menu";
import {RouteObject} from "react-router/lib/router";
import UserManage from "@/pages/system/user";
import RoleManage from "@/pages/system/role";
import JobManage from "@/pages/opt/job";
import DeptManage from "@/pages/system/dept";
import MenuManage from "@/pages/system/menu";
import DictManage from "@/pages/system/dict";
import LoginLog from "@/pages/system/log/login-log";
import OperateLog from "@/pages/system/log/operate-log";
import SystemLog from "@/pages/system/log/syslog";
import RedisMonitor from "@/pages/opt/redis";
import ProductManage from "@/pages/pms/product";
import BrandManage from "@/pages/pms/brand";
import CategoryManage from "@/pages/pms/category";
import OrderManage from "@/pages/oms/order";
import ReturnApplyManage from "@/pages/oms/return_apply";
import ReturnReasonManage from "@/pages/oms/return_reason";
import OrderSetting from "@/pages/oms/order_setting";
import CouponManage from "@/pages/sms/coupon";
import PromotionManage from "@/pages/sms/promotion";
import AdvertiseManage from "@/pages/sms/advertise";
import HomeBrandManage from "@/pages/sms/brand";
import HomeNewProductManage from "@/pages/sms/new_product";
import RecommendProductManage from "@/pages/sms/recommend_product";
import RecommendSubjectManage from "@/pages/sms/recommend_subject";
import MemberManage from "@/pages/ums/member";
import MemberAddressManage from "@/pages/ums/member_address";
import MemberLevelManage from "@/pages/ums/member_level";

const MemberLogManage = React.lazy(() => import("@/pages/ums/member_log"));

export function initRoutes(routes: any, menus: IMenu[]) {
  menus.map(item => {
    if (item.routes && item.routes.length > 0) {
      initRoutes(routes, item.routes);
    } else {
      routes.push(<Route key={item.path} path={item.path} element={<MemberLogManage/>}/>)
    }
  });
}

export const routeList = [
  <Route path="/product/manage/list" element={<MemberLogManage/>}/>,
  <Route path="/product/manage/brand" element={<MemberLogManage/>}/>
]

export const RouteMap = {
  '/product/manage/list': <Route path="/product/manage/list" element={<ProductManage/>}/>,
  '/product/manage/brand': <Route path="/product/manage/brand" element={<BrandManage/>}/>,
}

const element = (Node: any) => {
  return (
    <React.Suspense fallback={<div/>}>
      <Node/>
    </React.Suspense>
  )
}

const routeMapping = {
  '/product/manage/list': element(ProductManage),
  '/product/manage/brand': element(MemberLogManage)
}

const routes: RouteObject[] = [
  {path: '/product/manage/list', element: routeMapping['/product/manage/list']},
  {path: '/product/manage/brand', element: routeMapping['/product/manage/brand']},
]

const GetRoutes = () => {
  return useRoutes(routes)
}

export default GetRoutes

